/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Pessoa;
import model.Profissional;
import model.TipoUsuario;
import model.Usuario;
import model.UsuarioDAO;

/**
 *
 * @author Eduarda
 */
public class TrataUpdateUsuario extends Comando{

    @Override
    public void executar(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, IOException, ServletException {
       response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            response.setContentType("text/html");
            
            String senha = request.getParameter("senha");
            String login = request.getParameter("login");
            int profissional = Integer.parseInt(request.getParameter("profissional"));
            int tipo = Integer.parseInt(request.getParameter("tipo"));
            int idUsuario = Integer.parseInt(request.getParameter("idUsuario"));
            Usuario usua = new Usuario();
            usua.setLogin(login);
            usua.setSenha(senha);
            Pessoa pes  = new Pessoa(profissional, null, null, null, null, null, null, null, null);
            Profissional profissional2  = new Profissional(pes, 0, null, 0, null, null, null, null, null, null, null, null, null, null, null);
            TipoUsuario tipo2  = new TipoUsuario(tipo, null, null);
            usua.setTipoUsuario(tipo2);
            usua.setIdUsuario(idUsuario);
            usua.setProfissional(profissional2);
            new UsuarioDAO().editar(usua);
                
                
          //  HttpSession session = request.getSession(false);
            //session.setAttribute("Profissi", coord);
            //session.setAttribute("editado", coo);
            
            response.sendRedirect("usuarioEditado.jsp");  
        } catch (SQLException ex) {
            throw new ServletException(ex);
        } 
    }
    }
    
